package com.ssyt.yt1.day10.adapter;

/**
 * 插座
 * 
 * @author Administrator
 *
 */
class Socket1 {

	public void plugin(Plug1 plug) {
		plug.connect();
	}
}

/**
 * 插头
 * 
 * @author Administrator
 *
 */
interface Plug1 {

	void connect();
}

/**
 * 二孔插头
 * 
 * @author Administrator
 *
 */
class TwoHolePlug1 implements Plug1 {

	@Override
	public void connect() {
		System.out.println("二孔插头...");
	}
}

/**
 * 特殊的三孔插头
 * 
 * @author Administrator
 *
 */
class ThreeHolePlug1 {

	public void connection() {
		System.out.println("三孔插头...");
	}
}

/**
 * 适配器模式三：对象适配，跟适配器模式二类似，但它是通过组合实现
 * 
 * @author Administrator
 *
 */
class PlugAdapter1 implements Plug1 {

	private ThreeHolePlug1 threeHolePlug1;

	public PlugAdapter1(ThreeHolePlug1 threeHolePlug1) {
		super();
		this.threeHolePlug1 = threeHolePlug1;
	}

	@Override
	public void connect() {
		threeHolePlug1.connection();
	}
}

public class AdapterDemo3 {

	public static void main(String[] args) {
		new Socket1().plugin(new PlugAdapter1(new ThreeHolePlug1()));
	}
}
